﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BookEFCore
{
    public class MyDesignTimeDbContextFactory : IDesignTimeDbContextFactory<MyDbContext>
    {
        public MyDbContext CreateDbContext(string[] args = null)
        {
            var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
            string connStr = Environment.GetEnvironmentVariable("ConnectionStrings:BooksEFCore");
            // optionsBuilder.UseSqlServer("Server=.;Database=demo1;Trusted_Connection=True;MultipleActiveResultSets=true");
            if (connStr != null) optionsBuilder.UseSqlServer(connStr);
            else optionsBuilder.UseSqlServer("Server=.;Database=demo2;Trusted_Connection=True;MultipleActiveResultSets=true");
            return new MyDbContext(optionsBuilder.Options);
        }
    }
}
